package org.wechat4j.utils;

import com.alibaba.fastjson.JSON;
import org.wechat4j.exception.MpInvokeException;
import org.wechat4j.model.Response;

/**
 * @author bjliuyong
 * @version 1.0
 * @created date 16-11-14
 */
public class ResponseUtils {

    public static <T> T parse(String responseStr , Class<? extends Response> type) throws MpInvokeException{

        Response response = JSON.parseObject(responseStr ,type);

        if(!response.isSuccess())
            throw new MpInvokeException(response);

        return (T)response ;
    }

}
